/*---------------------------------------------------------
Royal Scoreboard 1.0
---------------------------------------------------------*/



PANEL = {}


AccessorFunc( PANEL, "m_bDeleteOnClose", 	"DeleteOnClose", 	FORCE_BOOL )


/*---------------------------------------------------------

---------------------------------------------------------*/
function PANEL:Init()

	self:SetFocusTopLevel( true )
	self.killsteama = 0
	self.killsteamb = 0
	self:SetPos((ScrW()/2)-340,ScrH()/5)
	self:SetSize(ScrW(),ScrH()-100)

	self.lblTitle = vgui.Create( "DLabel", self )
	self.lblTitle:SetPos(5,100)
	self.lblTitle:SetTextColor(Color(0,0,0,255))
	self.lblTitle:SetSize(250,20)
	self.lblTitle:SetText(GetHostName())

	self.List = vgui.Create("DPanelList",self)
	self.List:SetPos(20,190)
	self.List:SetSize(ScrW()/2-100,ScrH()/2)
	self.List:EnableVerticalScrollbar(true)
	//Scrollbar remove
	self.List.VBar.btnUp:SetVisible(false)
	self.List.VBar.btnDown:SetVisible(false)
	self.List.VBar.btnGrip:SetVisible(false)
	function self.List.VBar:Paint(w,h)
	surface.SetDrawColor(0,0,0,0)
	surface.DrawRect(0,0,w,h)
	return true
	end

	function self.List:Paint()
	surface.SetDrawColor(255,0,0,0)
	surface.DrawRect(0,0,self:GetWide(),self:GetTall())
	
	end


	//materials/scoreboard/logo.png
	self.col = {}

	self.col[1] = vgui.Create("DImage", self)
	self.col[1]:SetSize(100,50)
	self.col[1]:SetPos(40,120)
	self.col[1]:SetImage("scoreboard/score.png")

	self.col[2] = vgui.Create("DImage", self)
	self.col[2]:SetSize(100,50)
	self.col[2]:SetPos(240,120)
	self.col[2]:SetImage("scoreboard/ping.png")

	self.col[3] = vgui.Create("DImage", self)
	self.col[3]:SetSize(100,50)
	self.col[3]:SetPos(440,120)
	self.col[3]:SetImage("scoreboard/time.png")

	self.col[4] = vgui.Create("DImage", self)
	self.col[4]:SetSize(100,50)
	self.col[4]:SetPos(740,120)
	self.col[4]:SetImage("scoreboard/Name.png")

	self.col[5] = vgui.Create("DImage", self)
	self.col[5]:SetSize(350,80)
	self.col[5]:SetPos(5,5)
	self.col[5]:SetImage("scoreboard/logo.png")

	self.blank = 0
	self.rows = 0
	self.delay = 5
	self.lastupdate = CurTime() - 5
		self:Update()

end
/*---------------------------------------------------------

---------------------------------------------------------*/

/*---------------------------------------------------------

---------------------------------------------------------*/


/*---------------------------------------------------------

---------------------------------------------------------*/

function PANEL:Update()
tab = {}
for k,v in ipairs(player.GetAll()) do
	table.insert(tab, {Frags = v:Frags(),Play = v})
end

table.SortByMember( tab, "Frags" )

for k,v in ipairs(tab) do
	self:AddRow(v.Play)
	end

	self.lastupdate = CurTime()
end

/*---------------------------------------------------------

---------------------------------------------------------*/
function PANEL:ShowCloseButton( bShow )

	self.btnClose:SetVisible( bShow )

end

/*---------------------------------------------------------

---------------------------------------------------------*/
function PANEL:SetTitle( strTitle )

	self.lblTitle:SetText( strTitle )

end


/*---------------------------------------------------------

---------------------------------------------------------*/
function PANEL:Close()

	self:SetVisible( false )

	if ( self:GetDeleteOnClose() ) then
		self:Remove()
	end

end


/*---------------------------------------------------------

---------------------------------------------------------*/
function PANEL:Center()

	self:InvalidateLayout( true )
	self:SetPos( ScrW()/2 - self:GetWide()/2, ScrH()/2 - self:GetTall()/2 )

end


/*---------------------------------------------------------

---------------------------------------------------------*/
function PANEL:Think()
if(self.rows > 0 and CurTime() > self.lastupdate + self.delay ) then
Msg("sdakslj\n")
	self.List:Clear(true)
	self:Update()
end
Msg("nope\n")
	
end


/*---------------------------------------------------------
Draw the cool Header :D
---------------------------------------------------------*/
function PANEL:Paint()


	return true

end



/*---------------------------------------------------------

---------------------------------------------------------*/

function PANEL:AddRow(ply)

      local row = vgui.Create("quakerow",self.List)
	   	    row:SetPos(self:GetWide()/4+5,35+self.blank)
		    row:SetSize(300,30)
		    row:SetPlayer(ply)
				self.blank = self.blank + 40

			self.List:AddItem(row)
		  self.rows = self.rows + 1
	  self.ply = ply
end

/*---------------------------------------------------------

---------------------------------------------------------*/
function PANEL:PerformLayout()

	derma.SkinHook( "Layout", "Frame", self )

end

vgui.Register( "Quakeboard", PANEL, "Panel" )